﻿using System;
using System.Collections.Generic;
using System.Web.UI;
using visinia.SmartEngine;
using visinia.SmartEngine.Modules;
using viWiki.Classes;
using viWiki.Controllers;

public partial class Modules_viWiki_WikiPageList_WikiPageList : WebModule
{
    protected override void WebModuleRender(HtmlTextWriter output)
    {
        int count = WebHelpers.Int32ParseSafe((string)Settings["Count"], 3);
        if (count == 0)
            return;
         List<WikiPage> list = WikiPageController.GetWikiPagesByNamespace(Convert.ToInt32(Settings["Namespace"]));
        if (list == null)
            return;
        if(list.Count > count)
            list.RemoveRange(count, list.Count - count);
        List<string> text = new List<string>();
        List<string> links = new List<string>();
        foreach (WikiPage wikiPage in list)
        {
            text.Add(wikiPage.Name);
            links.Add(wikiPage.Url);
        }        
        string data = WebHelpers.GenerateBulletedListHyperLinks(text.ToArray(), links.ToArray());
        output.Write(data);
    }
}
